package co.yixiang.hw.repository;

import co.yixiang.hw.domain.SupplierGoodsSkuLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
* @author Walert
* @date 2021-03-27
*/
public interface SupplierGoodsSkuLogRepository extends JpaRepository<SupplierGoodsSkuLog, Long>, JpaSpecificationExecutor<SupplierGoodsSkuLog> {

    @Query(value = "select * from (select  " +
            "   change_time as changeTime,  " +
            "   max(first_source_price)        as firstSourcePrice, " +
            "   max(first_sale_price)          as firstSalePrice,  " +
            "   max(second_source_price)       as secondSourcePrice, " +
            "   max(second_sale_price)         as secondSalePrice,  " +
            "   max(thrid_source_price)        as thridSourcePrice, " +
            "   max(thrid_sale_price)          as thridSalePrice,  " +
            "   max(source_price)              as sourcePrice, " +
            "   max(sale_price)                as salePrice " +
            "   from supplier_goods_sku_log where sku_id = ?1 group by change_time order by change_time desc limit 0,30) t order by t.changeTime asc",nativeQuery = true)
    List<Map<String, BigInteger>> getPricesBySkuId(Long skuId);
}
